// pages/Livesharing/Livesharing.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vidimg: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    getApp().page.onLoad(this, e);
    this.live_qrcode()
  },
  live_qrcode(e) {
    var that = this
    getApp().request({
      url: getApp().api.share.live_qrcode,
      success: function (t) {
        if (t.code == 0) {
          that.setData({
            vidimg: t.data
          })
        }
      },
    });
  },
  bc: function (e) {
    var that = this
      var goods_qrcode = that.data.vidimg

    getApp().core.saveImageToPhotosAlbum ? (getApp().core.showLoading({
      title: "正在保存图片",
      mask: !1
    }), getApp().core.downloadFile({
      url: goods_qrcode,
      success: function (o) {
        getApp().core.showLoading({
          title: "正在保存图片",
          mask: !1
        }), getApp().core.saveImageToPhotosAlbum({
          filePath: o.tempFilePath,
          success: function () {
            getApp().core.showModal({
              title: "提示",
              content: "图片保存成功",
              showCancel: !1
            });
          },
          fail: function (o) {
            getApp().core.showModal({
              title: "图片保存失败",
              content: o.errMsg,
              showCancel: !1
            });
          },
          complete: function (o) {
            console.log('0000',o)
            getApp().core.hideLoading();
          }
        });
      },
      fail: function (o) {
        getApp().core.showModal({
          title: "图片下载失败",
          content: o.errMsg + ";" + goods_qrcode,
          showCancel: !1
        });
      },
      complete: function (o) {
        getApp().core.hideLoading();
      }
    })) : getApp().core.showModal({
      title: "提示",
      content: "当前版本过低，无法使用该功能，请升级到最新版本后重试。",
      showCancel: !1
    });
  },

  // baocun(e){
  //   var imgSrc =  this.data.vidimg;//base64编码
  //   var save = wx.getFileSystemManager();
  //   var number = Math.random();
  //   save.writeFile({
  //     filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  //     data: imgSrc,
  //     encoding: 'base64',
  //     success: res => {
  //       wx.saveImageToPhotosAlbum({
  //         filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
  //         success: function (res) {
  //           wx.showToast({
  //             title: '保存成功',
  //           })
  //         },
  //         fail: function (err) {
  //           console.log(err)
  //         }
  //       })
  //       console.log(res)
  //     }, fail: err => {
  //       console.log(err)
  //     }
  //   })
  // }

})